package com.li.commons.util;

import javax.servlet.http.HttpServletRequest;

public class DomainUtil {

    public static String getFullDomainName(HttpServletRequest request){
        return request.getServerName();
    }
    
    public static String getCommonDomain(HttpServletRequest request){
        String domain = request.getServerName();
        int index = domain.indexOf(".");
        if(index!=-1){
            domain = domain.substring(index);
        }
        return domain;
    }
    
    public static String getGenericsDomain(HttpServletRequest request) {
    	String domain = getFullDomainName(request);
        if (domain != null && domain.indexOf(".") > -1){
            return domain.substring(0, domain.indexOf("."));
        }
        return domain;
    }
    
    public static int getPort(HttpServletRequest request){
    	return request.getServerPort();
    }
}
